﻿Public Class MainForm

    Dim xhs() As String = Split(System.IO.File.ReadAllText("C:\Users\evo\Downloads\pbo\pbo\FarmWaletNew\FarmWaletNew\hs.txt"), vbCrLf)

    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label4.Text = xhs(0)
    End Sub

    Sub start()
        For xCountElm As Integer = 0 To Me.Controls.OfType(Of Pohon).Count() - 1
            Me.Controls.OfType(Of Pohon).ElementAt(xCountElm).start()
        Next
    End Sub

    Sub enableNextLevel()
        For xCountElm As Integer = 0 To Me.Controls.OfType(Of Pohon).Count() - 1
            Me.Controls.OfType(Of Pohon).ElementAt(xCountElm).stopTimer()
        Next

        Button2.Visible = True
    End Sub

    Sub checkWalet()
        Dim walet As Integer = 0
        For xCountElm As Integer = 0 To Me.Controls.OfType(Of Pohon).Count() - 1
            walet += Me.Controls.OfType(Of Pohon).ElementAt(xCountElm).countWalet()
        Next

        If walet = 0 Then
            MsgBox("Game Over, Skor anda " + Label2.Text)
            'Masukan Skor
            If Integer.Parse(Label2.Text) > Integer.Parse(xhs(0)) Then
                System.IO.File.WriteAllText("C:\Users\evo\Downloads\pbo\pbo\FarmWaletNew\FarmWaletNew\hs.txt", Label2.Text & vbCrLf)
            End If
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        start()
        Button1.Visible = False
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If Label2.Text = 32000 Then
            Dim pohon As New Pohon
            Controls.Add(pohon)
            pohon.Left = 646
            pohon.Top = 77
        ElseIf Label2.Text = 17000 Then
            Dim pohon2 As New Pohon
            Controls.Add(pohon2)
            pohon2.Left = 324
            pohon2.Top = 77
        End If
        Button2.Visible = False
        start()
    End Sub

End Class
